<template>
  <div>
    <template v-if="viewType === 'tree'">
      <TreeView ref="refTree" :actionId="actionId" />

      <!-- @change-menu="handleChangeMenu" -->
    </template>
  </div>
</template>

<script>
function sleep(millisecond) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve()
    }, millisecond)
  })
}

import api from '@/odoorpc'
import viewMixin from '@/odooui/viewMixin'
import TreeView from './ods_tree.vue'

export default {
  name: 'Web',
  components: {
    TreeView
    // FormView
  },
  mixins: [viewMixin],

  data() {
    return {
      actionId: undefined
      // actionId: 'fp_sale.action_fp_ods_sale_order'
    }
  },

  computed: {},

  watch: {
    // 菜单切换时, 触发
    '$route.fullPath': {
      handler: function (/*val*/) {
        console.log('in watch , $route.fullPath', this.$route.fullPath)
        // console.log('watch fullPath')
        // console.log('watch', )
        this.init()
        this.init_tree()
      },
      deep: true
    }
  },

  async created() {
    this.init_tree()
  },

  mounted() {},

  methods: {
    init_filter() {
      // todo 增加 默认过滤条件
    },

    async init_tree() {
      console.log('init,,,,')
      const actionId = api.tools.path2action_id(this.$route.path)

      this.actionId = actionId

      console.log('mounted', this.actionId)
      await sleep(100)

      const { activeIds } = this.$route.query
      await this.$refs.refTree.search_data(activeIds)

      this.$refs.refTree.activeIds = []
      this.$refs.refTree.showWizard()
    }

    // handleChangeMenu(...args) {
    //   this.$emit('change-menu', ...args)
    // }
  }
}
</script>

<style type="text/css"></style>
